﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_StdModelAssocPhrDict : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_EChartConfig_MainProjectConfig_ProjectConfigId",
                table: "EChartConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainOpenApiConfig_MainProjectConfig_ProjectConfigId",
                table: "MainOpenApiConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStConfig_MainProjectConfig_ProjectConfigId",
                table: "MainStConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdModelConfig_MainProjectConfig_ProjectConfigId",
                table: "MainStdModelConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdPhrDict_MainStdModelConfig_StdModelConfigId",
                table: "MainStdPhrDict");

            migrationBuilder.DropForeignKey(
                name: "FK_SfConfig_MainProjectConfig_ProjectConfigId",
                table: "SfConfig");

            migrationBuilder.DropTable(
                name: "MainProjectConfig");

            migrationBuilder.RenameColumn(
                name: "TEXT",
                table: "MainSysMenu",
                newName: "Text");

            migrationBuilder.RenameColumn(
                name: "SRTNO",
                table: "MainSysMenu",
                newName: "Srtno");

            migrationBuilder.RenameColumn(
                name: "LINK",
                table: "MainSysMenu",
                newName: "Link");

            migrationBuilder.RenameColumn(
                name: "ICON",
                table: "MainSysMenu",
                newName: "Icon");

            migrationBuilder.RenameColumn(
                name: "I18N",
                table: "MainSysMenu",
                newName: "I18n");

            migrationBuilder.RenameColumn(
                name: "GRP",
                table: "MainSysMenu",
                newName: "Grp");

            migrationBuilder.RenameColumn(
                name: "ROOT_FLAG",
                table: "MainSysMenu",
                newName: "RootFlag");

            migrationBuilder.RenameColumn(
                name: "MENU_TYPE",
                table: "MainSysMenu",
                newName: "MenuType");

            migrationBuilder.RenameColumn(
                name: "MENU_CODE",
                table: "MainSysMenu",
                newName: "MenuCode");

            migrationBuilder.RenameColumn(
                name: "LEAF_FLAG",
                table: "MainSysMenu",
                newName: "LeafFlag");

            migrationBuilder.RenameColumn(
                name: "HIDE_IN_BREADCRUMB_FLAG",
                table: "MainSysMenu",
                newName: "HideInBreadcrumbFlag");

            migrationBuilder.RenameIndex(
                name: "IX_MainSysMenu_MENU_CODE",
                table: "MainSysMenu",
                newName: "IX_MainSysMenu_MenuCode");

            migrationBuilder.RenameColumn(
                name: "StdModelConfigId",
                table: "MainStdPhrDict",
                newName: "StdModelAssocPhrDictId");

            migrationBuilder.RenameIndex(
                name: "IX_MainStdPhrDict_StdModelConfigId",
                table: "MainStdPhrDict",
                newName: "IX_MainStdPhrDict_StdModelAssocPhrDictId");

            migrationBuilder.RenameColumn(
                name: "ProjectConfigId",
                table: "MainStdModelConfig",
                newName: "TopicConfigId");

            migrationBuilder.RenameIndex(
                name: "IX_MainStdModelConfig_ProjectConfigId",
                table: "MainStdModelConfig",
                newName: "IX_MainStdModelConfig_TopicConfigId");

            migrationBuilder.AddColumn<int>(
                name: "ModelType",
                table: "MainStdModelConfig",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "MainStdModelAssocPhrDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StdModelConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdModelAssocPhrDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdModelAssocPhrDict_MainStdModelConfig_StdModelConfigId",
                        column: x => x.StdModelConfigId,
                        principalTable: "MainStdModelConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainTopicConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicName = table.Column<string>(type: "text", nullable: false),
                    NamespaceConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainTopicConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainTopicConfig_MainNamespaceConfig_NamespaceConfigId",
                        column: x => x.NamespaceConfigId,
                        principalTable: "MainNamespaceConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainTopicConfig_MainTopicConfig_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdModelAssocPhrDict_StdModelConfigId",
                table: "MainStdModelAssocPhrDict",
                column: "StdModelConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainTopicConfig_NamespaceConfigId",
                table: "MainTopicConfig",
                column: "NamespaceConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainTopicConfig_ParentId",
                table: "MainTopicConfig",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_EChartConfig_MainTopicConfig_ProjectConfigId",
                table: "EChartConfig",
                column: "ProjectConfigId",
                principalTable: "MainTopicConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainOpenApiConfig_MainTopicConfig_ProjectConfigId",
                table: "MainOpenApiConfig",
                column: "ProjectConfigId",
                principalTable: "MainTopicConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStConfig_MainTopicConfig_ProjectConfigId",
                table: "MainStConfig",
                column: "ProjectConfigId",
                principalTable: "MainTopicConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdModelConfig_MainTopicConfig_TopicConfigId",
                table: "MainStdModelConfig",
                column: "TopicConfigId",
                principalTable: "MainTopicConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdPhrDict_MainStdModelAssocPhrDict_StdModelAssocPhrDic~",
                table: "MainStdPhrDict",
                column: "StdModelAssocPhrDictId",
                principalTable: "MainStdModelAssocPhrDict",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_SfConfig_MainTopicConfig_ProjectConfigId",
                table: "SfConfig",
                column: "ProjectConfigId",
                principalTable: "MainTopicConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_EChartConfig_MainTopicConfig_ProjectConfigId",
                table: "EChartConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainOpenApiConfig_MainTopicConfig_ProjectConfigId",
                table: "MainOpenApiConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStConfig_MainTopicConfig_ProjectConfigId",
                table: "MainStConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdModelConfig_MainTopicConfig_TopicConfigId",
                table: "MainStdModelConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdPhrDict_MainStdModelAssocPhrDict_StdModelAssocPhrDic~",
                table: "MainStdPhrDict");

            migrationBuilder.DropForeignKey(
                name: "FK_SfConfig_MainTopicConfig_ProjectConfigId",
                table: "SfConfig");

            migrationBuilder.DropTable(
                name: "MainStdModelAssocPhrDict");

            migrationBuilder.DropTable(
                name: "MainTopicConfig");

            migrationBuilder.DropColumn(
                name: "ModelType",
                table: "MainStdModelConfig");

            migrationBuilder.RenameColumn(
                name: "Text",
                table: "MainSysMenu",
                newName: "TEXT");

            migrationBuilder.RenameColumn(
                name: "Srtno",
                table: "MainSysMenu",
                newName: "SRTNO");

            migrationBuilder.RenameColumn(
                name: "Link",
                table: "MainSysMenu",
                newName: "LINK");

            migrationBuilder.RenameColumn(
                name: "Icon",
                table: "MainSysMenu",
                newName: "ICON");

            migrationBuilder.RenameColumn(
                name: "I18n",
                table: "MainSysMenu",
                newName: "I18N");

            migrationBuilder.RenameColumn(
                name: "Grp",
                table: "MainSysMenu",
                newName: "GRP");

            migrationBuilder.RenameColumn(
                name: "RootFlag",
                table: "MainSysMenu",
                newName: "ROOT_FLAG");

            migrationBuilder.RenameColumn(
                name: "MenuType",
                table: "MainSysMenu",
                newName: "MENU_TYPE");

            migrationBuilder.RenameColumn(
                name: "MenuCode",
                table: "MainSysMenu",
                newName: "MENU_CODE");

            migrationBuilder.RenameColumn(
                name: "LeafFlag",
                table: "MainSysMenu",
                newName: "LEAF_FLAG");

            migrationBuilder.RenameColumn(
                name: "HideInBreadcrumbFlag",
                table: "MainSysMenu",
                newName: "HIDE_IN_BREADCRUMB_FLAG");

            migrationBuilder.RenameIndex(
                name: "IX_MainSysMenu_MenuCode",
                table: "MainSysMenu",
                newName: "IX_MainSysMenu_MENU_CODE");

            migrationBuilder.RenameColumn(
                name: "StdModelAssocPhrDictId",
                table: "MainStdPhrDict",
                newName: "StdModelConfigId");

            migrationBuilder.RenameIndex(
                name: "IX_MainStdPhrDict_StdModelAssocPhrDictId",
                table: "MainStdPhrDict",
                newName: "IX_MainStdPhrDict_StdModelConfigId");

            migrationBuilder.RenameColumn(
                name: "TopicConfigId",
                table: "MainStdModelConfig",
                newName: "ProjectConfigId");

            migrationBuilder.RenameIndex(
                name: "IX_MainStdModelConfig_TopicConfigId",
                table: "MainStdModelConfig",
                newName: "IX_MainStdModelConfig_ProjectConfigId");

            migrationBuilder.CreateTable(
                name: "MainProjectConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    NamespaceConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigType = table.Column<int>(type: "integer", nullable: false),
                    ProjectName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProjectConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainProjectConfig_MainNamespaceConfig_NamespaceConfigId",
                        column: x => x.NamespaceConfigId,
                        principalTable: "MainNamespaceConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainProjectConfig_NamespaceConfigId",
                table: "MainProjectConfig",
                column: "NamespaceConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_EChartConfig_MainProjectConfig_ProjectConfigId",
                table: "EChartConfig",
                column: "ProjectConfigId",
                principalTable: "MainProjectConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainOpenApiConfig_MainProjectConfig_ProjectConfigId",
                table: "MainOpenApiConfig",
                column: "ProjectConfigId",
                principalTable: "MainProjectConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStConfig_MainProjectConfig_ProjectConfigId",
                table: "MainStConfig",
                column: "ProjectConfigId",
                principalTable: "MainProjectConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdModelConfig_MainProjectConfig_ProjectConfigId",
                table: "MainStdModelConfig",
                column: "ProjectConfigId",
                principalTable: "MainProjectConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdPhrDict_MainStdModelConfig_StdModelConfigId",
                table: "MainStdPhrDict",
                column: "StdModelConfigId",
                principalTable: "MainStdModelConfig",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_SfConfig_MainProjectConfig_ProjectConfigId",
                table: "SfConfig",
                column: "ProjectConfigId",
                principalTable: "MainProjectConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
